<template>
  <div>
    <div class="vip_top">
      <div>
        <p>会员名称</p>
        <el-input
          placeholder="请输入内容"
          prefix-icon="el-icon-search"
          v-model="input2"
          @blur="blur"
        ></el-input>
      </div>
      <el-button type="primary" icon="el-icon-search" @click="search">
        查询
      </el-button>
    </div>
    <!-- 添加 -->
    <div>
      <button class="btn" @click="add">添加会员等级</button>
    </div>
    <!-- 列表 -->
    <div class="list_box">
      <el-table :data="tableData" border style="width: 100%;">
        <el-table-column
          fixed
          prop="grade"
          label="等级"
          width="149"
        ></el-table-column>
        <el-table-column
          prop="name"
          label="等级名称"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="condition"
          label="升级条件"
          width="220"
        ></el-table-column>
        <el-table-column
          prop="discount"
          label="折扣"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          width="270"
        ></el-table-column>
        <el-table-column prop="zip" label="邮编" width="120">
          <template slot-scope="scope">
            <span>查看详情</span>
            <el-button
              @click="handleClick(scope.row)"
              type="text"
              size="medium"
            >
              修改
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { zqhgrade } from '../../api/index'
export default {
  created() {
    this.list()
  },
  methods: {
    // 修改数据
    handleClick(row) {
      this.$router.push({ path: '/updategrade', query: row })
    },
    //   获取数据
    list() {
      zqhgrade({}).then((res) => {
        if (res.code == 200) {
          this.tableData = res.data
        }
      })
    },
    // 失去焦点
    blur(){
      this.list()
    },
    // 搜索
    search() {
      if (this.input2 != '') {
        this.tableData2 = this.tableData.filter((item) => {
          return item.grade == this.input2
        })
        this.tableData = this.tableData2
      }else{
        this.list()
      }
    },
    // 添加会员等级
    add(){
      this.$router.push('/postgrade')
    }
  },
  data() {
    return {
      input2: '',
      tableData: [],
    }
  },
}
</script>

<style lang="scss" scoped>
.vip_top {
  width: 450px;
  height: 50px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin: 30px 0 0 50px;
  div {
    display: flex;
    align-items: center;
    p {
      width: 90px;
    }
  }
}
.btn {
  width: 110px;
  height: 30px;
  border-radius: 5px;
  background-color: white;
  box-shadow: 1px 1px 2px gainsboro;
  border: 1px solid gainsboro;
  margin: 30px 0 0 100px;
}
.list_box {
  width: 1000px;
  margin: 30px auto;
}
</style>
